﻿Public Class MASCLSXRAY
    Private CXRYID = Nothing
    Private CODE = Nothing
    Private CXRYNAME = Nothing
    Private STATUS = Nothing
    Private SXRYID = Nothing
    Private XRYID As Integer = Nothing
    Private selectMasclsxray = "SELECT masclsxray.`cxryid` as 'ID ประเภท' , masclsxray.`CODE`, masclsxray.`cxryname` as 'ชื่อประเภท', masclsxray.`status` as 'สถานะการเปิดใช้งาน'FROM masclsxray "

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property XRYID_() As Integer
        Get
            Return XRYID
        End Get
        Set(value As Integer)
            XRYID = value
        End Set
    End Property

    Property SXRYID_() As Integer
        Get
            Return SXRYID
        End Get
        Set(value As Integer)
            SXRYID = value
        End Set
    End Property

    Property CXRYID_() As Integer
        Get
            Return CXRYID
        End Get
        Set(value As Integer)
            CXRYID = value
        End Set
    End Property

    Property CODE_() As String
        Get
            Return CODE
        End Get
        Set(value As String)
            CODE = value
        End Set
    End Property

    Property CXRYNAME_() As String
        Get
            Return CXRYNAME
        End Get
        Set(value As String)
            CXRYNAME = value
        End Set
    End Property

    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasclsxray_() As String
        Get
            Return selectMasclsxray
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasclsxrayData()
        If TypeOf CODE Is String And TypeOf CXRYNAME Is String Then
            If connect.GetTable("SELECT `cxryid` FROM masclsxray WHERE `code` = '" & CODE & "' AND cxryname = '" & CXRYNAME & "'  ").Rows.Count > 0 Then
                MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masclsxray (`code`, `cxryname`, `status`) VALUES ('" & CODE & "', '" & CXRYNAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

    Public Sub editMasclsxrayData()
            connect = CONDB.NewConnection()
            connect.BeginTrans()
        Try
            'Dim sql As String
            'connectlocal = conlocal.NewConnection()
            connect.ExecuteNonQuery("UPDATE masclsxray SET `code` = '" & CODE & "', `cxryname` = '" & CXRYNAME & "', `status` = '" & STATUS & "' WHERE `cxryid` = '" & CXRYID & "';")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            connect.CommitTrans()
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
            connect.Dispose()
            'connectlocal.Dispose()
    End Sub

    Public Sub editStatus(tableName As String, gridData As Boolean, fieldUpdate As String, whereField As String, whereValue As String)
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Try
            Dim sql As String
            sql = ("UPDATE masclsxray,xrayitem,maspartxray SET masclsxray.`status` ='" & STATUS & "',xrayitem.`status` ='" & STATUS & "',maspartxray.`status` ='" & STATUS & "' WHERE  masclsxray.`cxryid` ='" & CXRYID & "' AND  masclsxray.`cxryid` = maspartxray.`cxryid`  AND masclsxray.`cxryid` = xrayitem.`cxryid` ;")
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub

End Class
